package Pantallas;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import Controlador.controlador;

import Vista.ComidaView;
import Vista.RecetaView;
import Vista.SeccionView;




/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class modificarComida extends javax.swing.JFrame {
	private JLabel nomComida;
	private JComboBox comboNomComida;
	private JLabel tipoComida;
	private JLabel recetasComida;
	private JLabel secCocComida;
	private JTextField nomSeccion;
	private JTextField nomReceta;
	private JButton cancelar;
	private JButton aceptar;
	private JTextField textTipoComida;
	private JButton buscar;
	
	private Vector<ComidaView> comidasView;
	private Vector<RecetaView> recetasView;
	private Vector<SeccionView> seccionesView;
	
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				modificarComida inst = new modificarComida();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public modificarComida() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				nomComida = new JLabel();
				getContentPane().add(nomComida, "Center");
				nomComida.setText("Nombre Comida");
				nomComida.setLayout(null);
				nomComida.setBounds(19, 19, 152, 20);
			}
			{
				
				comboNomComida = new JComboBox();
				comidasView = controlador.getInstancia().getComidaView();
				getContentPane().add(comboNomComida);
				for(int i=0;i<comidasView.size();i++){
					comboNomComida.addItem(comidasView.elementAt(i).getNombre());
				}
				comboNomComida.setBounds(171, 18, 258, 23);						
			}
			{
				buscar = new JButton();
				getContentPane().add(buscar);
				buscar.setLayout(null);
				buscar.setText("Buscar");
				buscar.setBounds(452, 18, 118, 23);
				buscar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("buscar.actionPerformed, event="+evt);
						//TODO add your code for buscar.actionPerformed
						int index = comboNomComida.getSelectedIndex();
						ComidaView cv = comidasView.elementAt(index);
						textTipoComida.setText(cv.getTipoComida());
						nomSeccion.setText(cv.getSeccionCocina());
						nomReceta.setText(cv.getReceta());
					}
				});
			}
			{
				tipoComida = new JLabel();
				getContentPane().add(tipoComida);
				tipoComida.setText("Tipo Comida");
				tipoComida.setLayout(null);
				tipoComida.setBounds(12, 79, 123, 16);
			}
			{
				recetasComida = new JLabel();
				getContentPane().add(recetasComida);
				recetasComida.setText("Receta de la Comida");
				recetasComida.setLayout(null);
				recetasComida.setBounds(16, 129, 197, 16);
			}
			{
				secCocComida = new JLabel();
				getContentPane().add(secCocComida);
				secCocComida.setText("Seccion Cocina");
				secCocComida.setLayout(null);
				secCocComida.setBounds(20, 178, 152, 16);
			}
			{
				textTipoComida = new JTextField();
				getContentPane().add(textTipoComida);
				textTipoComida.setBounds(171, 76, 256, 23);
			}
			{
				aceptar = new JButton();
				getContentPane().add(aceptar);
				aceptar.setLayout(null);
				aceptar.setText("Aceptar");
				aceptar.setBounds(314, 226, 115, 23);
				aceptar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("aceptar.actionPerformed, event="+evt);
						int index = comboNomComida.getSelectedIndex();
						ComidaView cv = comidasView.elementAt(index);
						if(controlador.getInstancia().modComida(cv.getNombre(), textTipoComida.getText()))
							JOptionPane.showMessageDialog(null,"Se pudo modificar correctamente la comida.","Exito",JOptionPane.WARNING_MESSAGE);
						else
							JOptionPane.showMessageDialog(null,"No se pudo modificar correctamente la comida.","Exito",JOptionPane.WARNING_MESSAGE);
						dispose();
					}
				});
			}
			{
				cancelar = new JButton();
				getContentPane().add(cancelar);
				cancelar.setLayout(null);
				cancelar.setText("Cancelar");
				cancelar.setBounds(440, 226, 115, 23);
				cancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("cancelar.actionPerformed, event="+evt);
						//TODO add your code for cancelar.actionPerformed
						dispose();
					}
				});
			}
			{
				nomReceta = new JTextField();
				getContentPane().add(nomReceta);
				nomReceta.setBounds(173, 126, 253, 23);
				nomReceta.setEditable(false);
			}
			{
				nomSeccion = new JTextField();
				getContentPane().add(nomSeccion);
				nomSeccion.setBounds(171, 175, 255, 23);
				nomSeccion.setEditable(false);
			}
			pack();
			this.setSize(620, 308);
			this.setTitle("Modificar Comida");
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
